package com.geeksaga.service;

import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.geeksaga.dao.BbsManagerDao;
import com.geeksaga.dao.BbsTypeDao;
import com.geeksaga.domain.Bbs;
import com.geeksaga.domain.BbsManager;
import com.geeksaga.domain.BbsType;

/**
 * @author newbie, casper
 * @since 0.1
 */
@Service
public class BbsManagerServiceImpl implements BbsManagerService {
    
    @Autowired protected BbsManagerDao bbsManagerDao;
    @Autowired protected BbsTypeDao bbsTypeDao;

    /* (non-Javadoc)
     * @see com.geeksaga.service.BbsManagerService#add(com.geeksaga.domain.BbsManager)
     */
    public BbsManager add(BbsManager manager) throws DataAccessException {
        return bbsManagerDao.add(manager);
    }

    /* (non-Javadoc)
     * @see com.geeksaga.service.BbsManagerService#isManager(com.geeksaga.domain.Bbs, com.geeksaga.domain.BbsType)
     */
    public boolean isManager(Bbs bbs, BbsType type) throws DataAccessException {
    	if(type == null)
    		return false;
    	
        Map<String, String> manager = bbsManagerDao.findByBbsType(type);
        String bbsId = manager.get(bbs.getUserSid());
        
        if(bbs != null && bbs.getBbsId().equals(bbsId))
            return true;
        
        return false;
    }
}